function do_google_menus() {

// key: word to match, value a dictionary of style elements to apply
// to blocks containing that word.
const COLOR_MAP = {
  "garlic": {"color": "red"},
};

const TITLE_REPLACE = {
  "MOMA | ": "",
};

function highlightText() {

  var allTextNodes = document.evaluate('//text()', document, null,
                                       XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                                       null);

  for (var i = 0; i < allTextNodes.snapshotLength; i++) {
    var ele = allTextNodes.snapshotItem(i);
    for (var key in COLOR_MAP) {
      if (ele.nodeValue.toLowerCase().indexOf(key) != -1) {
        // TODO(ark) perhaps make it only highlight the word?
        var span = document.createElement("span");
        ele.parentNode.replaceChild(span, ele);
        span.appendChild(ele);
        for (var css in COLOR_MAP[key]) {
          span.style[css] = COLOR_MAP[key][css];
        }
      }
    }
  }
}

function replaceTitle() {

  for (var key in TITLE_REPLACE) {
    document.title = document.title.replace(key, TITLE_REPLACE[key]);
  }
}

function documentContains(needle) {
  var allTextNodes = document.evaluate('//text()', document, null,
                                       XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                                       null);


  needle = needle.toLowerCase();

  for (var i = 0; i < allTextNodes.snapshotLength; i++) {
    var ele = allTextNodes.snapshotItem(i);
    if (ele.nodeValue.toLowerCase().match(needle)) {
      return true;
    }
  }
  return false;
}

function makeSureTodayIsMentioned() {
  var m = ["January", "February", "March", "April", "May", "June",
           "July", "August", "September", "October", "November", "December"];
  var d = new Date();
  var today = m[d.getMonth()] + " 0?" + d.getDate() + ", " + d.getFullYear();

  if (!documentContains(today) ||
      !(documentContains('Lunch +Menu') ||
        documentContains('Lunch +for') ||
        documentContains('page content last updated')) ||
      false) {
    document.bgColor = "#c9c9c9";
  }
}

highlightText();
replaceTitle();

if (!String(document.location).match('menumon') &&
    String(document.location).indexOf('~') != -1) {
  makeSureTodayIsMentioned();
}

};

window.setTimeout(do_google_menus, 2000);

